﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using ProductionManage.Models.Products;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using wangyaxin.Wang.Dto;
using wangyaxin.Zhangduo.MdItemType;
using wangyaxin.Zhangduo.MdItemType.Dto;
using static Volo.Abp.Identity.Settings.IdentitySettingNames;

namespace wangyaxin.Zhangduo
{
    [ApiExplorerSettings(GroupName = "张铎")]
    public class MdItemTypeService:ApplicationService,IMdItemTypeAppService
    {
        public readonly IRepository<ProductType, int> _ProductTyperepository;
        public readonly IRepository<Product, int> _Productpository;

        public MdItemTypeService(IRepository<ProductType, int> productTyperepository,IRepository<Product,int> productpository)
        {
            _ProductTyperepository = productTyperepository;
            _Productpository = productpository;
        }
        /// <summary>
        /// 显示物料产品分类
        /// </summary>
        /// <param name="typeName">分类名称</param>
        /// <param name="stauct">是否启用</param>
        /// <returns>返回满足条件数据</returns>
        [HttpGet, Route("GetProducts")]
        public async Task<string> GetProducts(string? typeName, string? stauct)
        {
            var Products = await _ProductTyperepository.GetListAsync();
            if(!string.IsNullOrEmpty(typeName))
            {
                Products = Products.Where(c => c.TypeName.Contains(typeName)).ToList();
            }
            if(!string.IsNullOrEmpty(stauct))
            {
                bool Stauct=Convert.ToBoolean(stauct);
                Products = Products.Where(c => c.IsEnable== Stauct).ToList();
            }
            var productList = ObjectMapper.Map<List<ProductType>, List<MdItemTypeDto>>(Products);
            return JsonConvert.SerializeObject(new PageDto<MdItemTypeDto> { code = "", data = productList, msg = "", count = productList.Count }); 
        }
    }
}
